//
// Created by 王乐 on 2022/2/9.
//

#include "LeParticleGameObject.h"
#include "LeParticleBehaviour.h"
#include "LeMoveShadowRenderer.h"

LeParticle::LeParticle(const std::string& mName, float mLiftTime, const glm::vec3 &mStartPosition, float mStartRotation,
                       const glm::vec3 &mStartScale, const glm::vec3 &mVelocity, float mAngularSpeed,
                       float mScaleChangeRatio, const char *mSpritePath) : m_Name(mName),m_LiftTime(mLiftTime),
                                                                           m_StartPosition(mStartPosition),
                                                                           m_StartRotation(mStartRotation),
                                                                           m_StartScale(mStartScale),
                                                                           m_Velocity(mVelocity),
                                                                           m_AngularSpeed(mAngularSpeed),
                                                                           m_ScaleChangeValue(mScaleChangeRatio),
                                                                           m_SpritePath(mSpritePath)
{}

LeParticle::LeParticle(const std::string& mName, float mLiftTime, const glm::vec3 &mVelocity, float mAngularSpeed, float mScaleChangeValue,
                       const char *mSpritePath) : m_Name(mName),m_LiftTime(mLiftTime), m_Velocity(mVelocity),
                                                  m_AngularSpeed(mAngularSpeed), m_ScaleChangeValue(mScaleChangeValue),
                                                  m_SpritePath(mSpritePath)
{}

LeParticleGameObject::LeParticleGameObject(LeParticleSystem* pParticleSystem) :
    m_pParticleSystem(pParticleSystem)
{

}

LeParticleGameObject::~LeParticleGameObject()
{

}

void LeParticleGameObject::Initialize()
{
    strName = "MyParticle";

    // Transform
    // ---------
    m_Transform.setPosition(m_Particle.m_StartPosition.x, m_Particle.m_StartPosition.y, m_Particle.m_StartPosition.z);
    m_Transform.setScale(m_Particle.m_StartScale.x, m_Particle.m_StartScale.y, m_Particle.m_StartScale.z);
    m_Transform.setRotation(0, 0, m_Particle.m_StartRotation);

    LeMoveShadowRenderer* pRenderer = new LeMoveShadowRenderer();
    pRenderer->initRenderer(this, m_VertexShaderPath, m_FragmentShaderPath);
    pRenderer->addSprite(m_Particle.m_SpritePath);

    // Behaviour
    // ---------
    LeParticleBehaviour* pBehaviour = new LeParticleBehaviour();

    // Initialize Components
    initComponents(pRenderer, nullptr, pBehaviour, nullptr);
}

void LeParticleGameObject::InitializeParticleGameObject(const char *vertexshaderpath, const char *fragmentshaderpath,
                                                        const LeParticle &particle)
{
    m_VertexShaderPath = vertexshaderpath;
    m_FragmentShaderPath = fragmentshaderpath;
    m_Particle = particle;
    m_bIsActive = false;
}

LeParticleSystem *LeParticleGameObject::getParticleSystem()
{
    return m_pParticleSystem;
}
